package com.yjjxt

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Hello08Union {
  def main(args: Array[String]): Unit = {
    //1.配置并创建对象
    val sparkConf = new SparkConf()
      .setMaster("spark://node01:7077")
      .setAppName("Join" + System.currentTimeMillis())
    val sparkContext = new SparkContext(sparkConf)

    val array1 = Array[String]("Hello1 user1", "Hello2 user1", "Hello user11", "Hello user12", "user1 apple1")
    val array2 = Array[String]("Hello1 user2", "Hello2 user2", "Hello user21", "Hello user22", "user2 apple2")
    val lines1 = sparkContext.parallelize(array1, 2)
    val lines2 = sparkContext.parallelize(array2, 3)
    //Union合并到一起
    val line: RDD[String] = lines1.union(lines2)
    println("line1=>" + lines1.getNumPartitions)
    println("line2=>" + lines2.getNumPartitions)
    println("line=>" + line.getNumPartitions)
    line.foreach(println)

    //查看分区
    sparkContext.stop()
  }
}
